package com.yuetong.inventory.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yuetong.common.annotation.Log;
import com.yuetong.common.core.controller.BaseController;
import com.yuetong.common.core.domain.AjaxResult;
import com.yuetong.common.enums.BusinessType;
import com.yuetong.inventory.domain.YtInventoryHistory;
import com.yuetong.inventory.service.IYtInventoryHistoryService;
import com.yuetong.common.utils.poi.ExcelUtil;
import com.yuetong.common.core.page.TableDataInfo;

/**
 * 出入库记录Controller
 *
 * @author  卓晓君
 * @date 2025-03-21
 */
@RestController
@RequestMapping("/inventory/history")
public class YtInventoryHistoryController extends BaseController
{
    @Autowired
    private IYtInventoryHistoryService ytInventoryHistoryService;

    /**
     * 查询出入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('inventory:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(YtInventoryHistory ytInventoryHistory)
    {
        startPage();
        List<YtInventoryHistory> list = ytInventoryHistoryService.selectYtInventoryHistoryList(ytInventoryHistory);
        return getDataTable(list);
    }

    /**
     * 导出出入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('inventory:history:export')")
    @Log(title = "出入库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YtInventoryHistory ytInventoryHistory)
    {
        List<YtInventoryHistory> list = ytInventoryHistoryService.selectYtInventoryHistoryList(ytInventoryHistory);
        ExcelUtil<YtInventoryHistory> util = new ExcelUtil<YtInventoryHistory>(YtInventoryHistory.class);
        util.exportExcel(response, list, "出入库记录数据");
    }

    /**
     * 获取出入库记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('inventory:history:query')")
    @GetMapping(value = "/{historyId}")
    public AjaxResult getInfo(@PathVariable("historyId") Long historyId)
    {
        return success(ytInventoryHistoryService.selectYtInventoryHistoryByHistoryId(historyId));
    }

    /**
     * 新增出入库记录
     */
    @PreAuthorize("@ss.hasPermi('inventory:history:add')")
    @Log(title = "出入库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YtInventoryHistory ytInventoryHistory)
    {
        return toAjax(ytInventoryHistoryService.insertYtInventoryHistory(ytInventoryHistory));
    }

    /**
     * 修改出入库记录
     */
    @PreAuthorize("@ss.hasPermi('inventory:history:edit')")
    @Log(title = "出入库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YtInventoryHistory ytInventoryHistory)
    {
        return toAjax(ytInventoryHistoryService.updateYtInventoryHistory(ytInventoryHistory));
    }

    /**
     * 删除出入库记录
     */
    @PreAuthorize("@ss.hasPermi('inventory:history:remove')")
    @Log(title = "出入库记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{historyIds}")
    public AjaxResult remove(@PathVariable Long[] historyIds)
    {
        return toAjax(ytInventoryHistoryService.deleteYtInventoryHistoryByHistoryIds(historyIds));
    }
}
